<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script>
	var tables = $('#dataTables').DataTable({
		"sAjaxSource" : '{{ urlfor "EntryreturnController.Confirmout"}}'
		,"bLengthChange": false
		,"fnServerData" : function(sSource, aoData, fnCallback) {
			var params = checkQueryTableData(aoData);
			
			$('#search_key').val() ? params.Filter = $('#search_key').val() : '';
			$('#auditing').val()!='' ? params.Auditing = $('#auditing').val() : '';
			$('#typeid').val()!='' ? params.Typeid = $('#typeid').val() : '';
			
			$.post(sSource, JSON.stringify(params),function(resp) {
				fnCallback(resp);
			},'json')
		}
		,columns: [
			{"data" : "Number", "bSortable": false, render:function(data, type, full, meta) {
				return data;
			}}
			,{"bSortable": false, render:function(data, type, full, meta) {
				return '<a href="javascript:;" data-am-popover="{content: \''+ full.Suppliers.Name +'<br />联系人：'+ full.Suppliers.Contacts +'<br />电话：'+ full.Suppliers.Tel +'\', trigger: \'hover focus\'}">'+ full.Suppliers.Name +'</a>';
				
			}}
			,{"data" : "ProNumber", "bSortable": false}
			,{"data" : "CreatedAt", "bSortable": false, render:function(data, type, full, meta) {
				return full.CreatedBy + ' ' + timetransDate(data);	
			}}
			,{"data" : "UpdatedAt", "bSortable": false, render:function(data, type, full, meta) {
				return full.UpdatedBy + ' ' + timetransDate(data);	
			}}
			,{   
				"mDataProp": "Action", 
				"bSortable": false, 
				"sWidth":"10%",
				"render": function ( data, type, full, meta ) { 
					btns = '';
                    btns += '&nbsp;<a class="am-btn am-btn-success am-btn-xs" href="{{ urlfor "EntryreturnController.ViewOut"}}/' + full.Id + '">出库</a>';
					return btns;
				}
			 } 
		]
		,"aLengthMenu":[20, 50, 100, 200]
		,'bLengthChange': true
		,"serverSide": true
		,"bPaginate" : true
		,"bFilter" : false	//是否启动过滤、搜索功能 
		,"bInfo" : true //是否显示页脚信息，DataTables插件左下角显示记录数
		,"bProcessing" : true //DataTables载入数据时，是否显示‘进度’提示  
		,"drawCallback": function(settings){
			$('[data-am-popover]').popover();
		}   
	});
	
	$("#searchsubmit").bind("click", function () { //点击按钮 触发table重新请求服务器
		$("#dataTables").dataTable().fnDraw(false);
	});

	function dialogReback() {
		tables.ajax.reload();
	}
	
	$('#insert-entry').click(function(){
		var url = '{{urlfor "EntryreturnController.SelectSuppliers"}}';
		
		layer.open({
            type: 2,
            title: '选对供应商',
            shadeClose: false,
            shade: 0.2,
            maxmin: false,
            shift: 1,
            area: ['410px', '436px'],
            content: url
        });
		
		return false;	
	});
	function delRereat(id) {
	    layer.confirm("确定要删除该退货单吗？", function(index){
            $.post('{{urlfor "EntryreturnController.DelRereat"}}', {id:id}, function(res){
                if(res.code == 1) {
                    layer.alert(res.msg);
                    return false;
                }
                layer.close(index);
                $("#searchsubmit").click();
            });
        });
        return false;
    }
	function SelectSuppliersRollBack(id) {
		layer.closeAll();
		location = '{{ urlfor "EntryreturnController.Edit" }}/'+id;
	}
</script>